home *** CD-ROM | disk | FTP | other *** search
/ SunSoft Catalyst CDWARE 1996 May to August / Catalyst CDWARE 1996 May to August.iso / .products / .bin / httpd / Solaris_1 / marc.pl < prev    next >
Perl Script  |  1996-02-29  |  25KB  |  795 lines

  1. #!./perl
  2. ## Make a gif "transparent"
  3. ##
  4. ## Jeffrey Friedl
  5. ## jfriedl@omrongw.wg.omron.co.jp
  6. ## 15 July 1994
  7. ## 2 Aug 1994 - added ability to select transparent color by RGB values.
  8. ## 940825.3 -- modified to work with possible future versions of the
  9. ##             GIF standard... just in case.
  10. ##
  11. #$version = "940825.3";
  12. ##
  13. ## BLURB:
  14. ## Transforms a "normal" gif into a "transparent background" gif.
  15. ##
  16. ##>
  17. ##
  18. ## I wrote this because people ask for something like this all the time.
  19. ## I just learned the format of GIFs a week ago, so this will likely be
  20. ## lacking in many respects.
  21. ##
  22. ##
  23. ## Usage:
  24. ##      transgif [options] regular.gif > transparent.gif
  25. ##   or
  26. ##      cat regular.gif | transgif [options] transparent.gif
  27. ##
  28. ## The default is that whatever color happens to fall into the first colormap
  29. ## slot (often black) will be made transparent. This can be changed via the
  30. ## the options.
  31. ##
  32. ## The options are from:
  33. ##   -p              print the colormap (to STDERR).
  34. ##             The new gif still goes to STDOUT.
  35. ##
  36. ##   -###            make colormap index-### transparent (default is -0)
  37. ##
  38. ##   -rgb ## ## ##   Take the three numbers as R G B values (in the range
  39. ##             of 0..255 (or 0x00..0xff). The first colormap entry
  40. ##             with those RGB values is made transparent.
  41. ##
  42. ##   -rgb name       Use the R G B values of the color 'name' if known
  43. ##             by this program (data from X11's rgb.txt)
  44. ##
  45. ## COLORNUM is the index of the color entry to make transparent, and 
  46. ## defaults to zero. For those that like the looks of it, you can put
  47. ## a leading '-'.
  48. ##
  49. ##<
  50.  
  51. sub usage {
  52.    die "@_\nUsage: $0 [-p] [-## | -rgb name | -rgb ## ## ##] [file]\n";
  53. }
  54.  
  55. $trans_index = 0;
  56. $print_color_map = 0;
  57. $select_via_rgb = 0;
  58.  
  59. while (@ARGV && $ARGV[0] =~ m/^-/) {
  60.     $arg = shift;
  61.     if ($arg eq '-p') {          ## print color map
  62.     $print_color_map = 1;
  63.  
  64.     } elsif ($arg =~ m/^-(\d+)$/) {  ## set color map index number
  65.     $trans_index = $1;
  66.  
  67.     } elsif ($arg eq '-rgb') {         ## set what color to make transparent
  68.  
  69.     ## if next three args look numerical (## or 0x##), use as R B G.
  70.     if (@ARGV >= 3 &&
  71.         $ARGV[0] =~ m/^(0x[\da-f]+|\d+)$/i &&
  72.         $ARGV[1] =~ m/^(0x[\da-f]+|\d+)$/i &&
  73.         $ARGV[2] =~ m/^(0x[\da-f]+|\d+)$/i)
  74.     {
  75.         ($R, $G, $B) = splice(@ARGV, 0, 3);
  76.         $select_via_rgb = 1;
  77.         $R = eval($R); ## eval these to process any hex or octal values.
  78.         $G = eval($G); ## eval these to process any hex or octal values.
  79.         $B = eval($B); ## eval these to process any hex or octal values.
  80.  
  81.     ## if next arg looks like a color name, use those R G B values.
  82.     } elsif (@ARGV && (@RGB = &name2rgb($ARGV[0]), @RGB == 3)) {
  83.         shift; ## eat name;
  84.         ($R, $G, $B) = @RGB;
  85.         $select_via_rgb = 1;
  86.  
  87.     } else {
  88.        warn(qq/(don't understand "$ARGV[0]" as a color name)\n/) if @ARGV;
  89.        die qq/$0: expected color name or a numerical triplet for $arg\n/;
  90.     }
  91.     } else {
  92.     &usage(qq/unknown arg "$arg".\n/);
  93.     }
  94. }
  95.  
  96. &usage('too many args.') if @ARGV > 1;
  97.  
  98. if (@ARGV == 0) {
  99.     &giftrans(*STDIN, *STDOUT, $trans_index);
  100. } else {
  101.     open(INPUT,  $file =shift) || die "$0: couldn't open [$file] for input\n";
  102.     &giftrans(*INPUT, *STDOUT, $trans_index);
  103.     close(INPUT);
  104. }
  105. exit(0);
  106.  
  107.  
  108.  
  109. ##
  110. ## Given indirect references to two filehandles, pass the file from
  111. ## one to the other, changing nothing unless it's a GIF that we know
  112. ## how to deal with, and if so do so.
  113. ##
  114. ## This is written rather verbosely for the sake of clarity... speed not
  115. ## much of an issue for something like this, and the difference is minimal
  116. ## anyway.
  117. ##
  118. sub giftrans
  119. {
  120.     local(*IN, *OUT, $trans_index) = @_;
  121.     $trans_index = 0 if !defined $trans_index;
  122.     local($header, $color_table, $nextblock, $buffer) = ('') x 4;
  123.  
  124.     ## The header looks like:
  125.     ##   byte 0 - 5:  "GIF89a" or "GIF87a"
  126.     ##   byte 6, 7:   width  (low order first)
  127.     ##   byte 8, 9:   height (low order first)
  128.     ##   byte 10:     various flags
  129.     ##   byte 11:     background color index
  130.     ##   byte 12:     aspect ratio
  131.     sysread(IN, $header, 13) || die "sysread header: $!";
  132.     substr($header, 0, 6) = 'GIF89a' if substr($header,0,6) eq 'GIF87a';
  133.     print OUT $header;
  134.  
  135.     if (substr($header, 0, 3) ne 'GIF') {
  136.     print STDERR "don't know input filetype, passing unchanged\n";
  137.     } else {
  138.     ##
  139.     ## Look at flags (8 bits): hi[MCCCSPPP]low
  140.     ##   M   = global colormap present?
  141.     ##   CCC = bits/color/colormapentry - 1
  142.     ##   S   = color map sorted by importance?
  143.     ##   PPP = bits/pixel - 1
  144.     ## therefore
  145.     ##   Bits/pixel = PPP+1
  146.     ##   Number of possible colors (entries in colormap): 2 ** (PPP+1)
  147.     ##                                                  : 1 << (PPP+1)
  148.     ##   Size (bytes) of colormap: 3 * Number of possible colors
  149.     ##                           : 3 * (1 << (PPP+1))
  150.     ##
  151.     local($flags) = ord(substr($header, 10, 1));
  152.     local($has_global_colormap) = $flags & 0x80;
  153.  
  154.     ## Copy over the colormap if need be.
  155.     if (!$has_global_colormap)
  156.     {
  157.        die "$0: picture has no colormap, so -rgb arg invalid\n"
  158.         if $select_via_rgb;
  159.        die "$0: no colormap, so any index except 0 or 1 makes no sense\n"
  160.         if $trans_index > 1;
  161.     } else {
  162.         local($bits_per_pixel) = 1 + ($flags & 0x07);
  163.         local($colormap_entries) = 1 << $bits_per_pixel;
  164.         local($color_tbl_size) = 3 * $colormap_entries;
  165.  
  166.         sysread(IN, $color_table, $color_tbl_size) || die "sysread color";
  167.         print OUT $color_table;
  168.  
  169.         if ($print_color_map || $select_via_rgb)
  170.         {
  171.         ## For each byte of each colormap's RGB triplit, we'll have
  172.         ## to mask off bits that aren't used when looking at the
  173.         ## color values.
  174.         local($bits_color_byte) = 1 + (($flags >> 4) & 0x07);
  175.         local($rgb_byte_mask) = (1 << $bits_color_byte) - 1;
  176.         local($r,$g,$b);
  177.  
  178.         local($best_delta) = 1000; ## any big number ok
  179.         local(@delta, @r, @b, @g);
  180.  
  181.         for ($i = 0; $i < $colormap_entries; $i++)
  182.         {
  183.            ($r, $g, $b) = unpack("CCC", substr($color_table, $i*3, 3));
  184.            $r &= $rgb_byte_mask;
  185.            $g &= $rgb_byte_mask;
  186.            $b &= $rgb_byte_mask;
  187.  
  188.            if ($select_via_rgb) {
  189.             if ($r == $R && $g == $G && $b == $B) {
  190.                 $select_via_rgb = 0;
  191.                 $trans_index = $i;
  192.                 print(STDERR "Found exact match (index #$i).\n");
  193.             } else {
  194.                 $delta = ($r < $R ? $R - $r : $r - $R) +
  195.                      ($g < $G ? $G - $g : $g - $G) +
  196.                      ($b < $B ? $B - $b : $b - $B);
  197.                 if ($delta < $best_delta) {
  198.                 @delta = ($i);
  199.                 @r = $r; @g = $g; @b = $b;
  200.                 $best_delta = $delta;
  201.                 } elsif ($delta == $best_delta) {
  202.                 push(@delta, $i);
  203.                 push(@r, $r); push(@g, $g); push(@b, $b);
  204.                 }
  205.             }
  206.            }
  207.  
  208.            printf(STDERR "%03d: %3d %3d %3d (x%02x x%02x x%02x)\n", $i,
  209.             $r, $g, $b, $r, $g, $b) if $print_color_map;
  210.         }
  211.  
  212.         if ($select_via_rgb) {
  213.             ## Mmm, didn't find it. Use one of the close ones.
  214.             $trans_index = shift(delta);
  215.             $r = shift(@r);
  216.             $g = shift(@g);
  217.             $b = shift(@b);
  218.  
  219.             printf(STDERR "requested color not found, using index ".
  220.                   "#%d: %3d %3d %3d (x%02x x%02x x%02x)\n",
  221.                   $trans_index,
  222.                    $r, $g, $b, $r, $g, $b);
  223.             if (@delta)
  224.             {
  225.             $count = @delta;
  226.             print(STDERR
  227.                 "note: %d other entrie%s seem equally close:\n",
  228.                 $count, $count == 1 ? "" : "s");
  229.             while (@delta) {
  230.                 $index = shift(delta);
  231.                 $r = shift(@r);
  232.                 $g = shift(@g);
  233.                 $b = shift(@b);
  234.                    printf(STDERR "  index %03d: %3d %3d %3d ".
  235.                       "(x%02x x%02x x%02x)\n",
  236.                       $index, $r, $g, $b, $r, $g, $b);
  237.             }
  238.             }
  239.         }
  240.         }
  241.     }
  242.  
  243.     ##
  244.     ## The next 8 bytes will either be an already-there graphic-extension
  245.     ## block, or something else that we'll not care about. In the latter
  246.     ## case, we'll add a graphic-extension block saying "color such-and-
  247.     ## such is transparent". If there's already one there, we'll just
  248.     ## ensure that it says that.
  249.     ##
  250.     sysread(IN, $nextblock, 8) || die "sysread nextblock";
  251.     local($extension, $label) = unpack('CC', $nextblock);
  252.     ## If extension is 0x21 and label is 0xf9, that's the magic tha means
  253.     ## there's already a graphic extension there.
  254.     if ($extension == 0x21 && $label == 0xf9) {
  255.         substr($nextblock, 3, 1) = pack('C', 1|substr($nextblock, 3, 1));
  256.         substr($nextblock, 6, 1) = pack('C', $trans_index);
  257.     } else {
  258.         print OUT pack('CCC CCCC C',
  259.         0x21,  ## magic: "Extension Introducer"
  260.         0xf9,  ## magic: "Graphic Control Label"
  261.            4,  ## bytes in block (between here and terminator)
  262.         0x01,  ## indicates that 'transparet index' is given
  263.         0, 0,  ## delay time.
  264.                 $trans_index, ## index number of colormap entry
  265.         0x00); ## terminator.
  266.     }
  267.     print OUT $nextblock;
  268.     }
  269.  
  270.     ## Now just pass the rest of the file over unchanged.
  271.  
  272.     print OUT $buffer while sysread(IN, $buffer, 4096);
  273.     close(IN);
  274.     close(OUT);
  275. }
  276.  
  277. ##
  278. ## Change a name to a triplet of RGB values.
  279. ## name and RGB data taken from the X11 lib/rgb.txt, with the
  280. ## name regexe-compressed by me.
  281. ##
  282. sub name2rgb
  283. {
  284.     local($_) = @_;  ## name;
  285.     study;
  286.     %rgb = (
  287.     '  0,  0,  0', 'black|gr[ae]y0',
  288.     '  0,  0,128', 'navy([ \-]?blue)?',
  289.     '  0,  0,139', 'blue4',
  290.     '  0,  0,205', 'blue3|medium[ \-]?blue',
  291.     '  0,  0,238', 'blue2',
  292.     '  0,  0,255', 'blue1?',
  293.     '  0,100,  0', 'dark[ \-]?green',
  294.     '  0,104,139', 'deepskyblue4',
  295.     '  0,134,139', 'turquoise4',
  296.     '  0,139,  0', 'green4',
  297.     '  0,139, 69', 'springgreen4',
  298.     '  0,139,139', 'cyan4',
  299.     '  0,154,205', 'deepskyblue3',
  300.     '  0,178,238', 'deepskyblue2',
  301.     '  0,191,255', 'deep( sky blue|-sky-blue|skyblue1?)',
  302.     '  0,197,205', 'turquoise3',
  303.     '  0,205,  0', 'green3',
  304.     '  0,205,102', 'springgreen3',
  305.     '  0,205,205', 'cyan3',
  306.     '  0,206,209', 'dark[ \-]?turquoise',
  307.     '  0,229,238', 'turquoise2',
  308.     '  0,238,  0', 'green2',
  309.     '  0,238,118', 'springgreen2',
  310.     '  0,238,238', 'cyan2',
  311.     '  0,245,255', 'turquoise1',
  312.     '  0,250,154', 'medium[ \-]?spring[ \-]?green',
  313.     '  0,255,  0', 'green1?',
  314.     '  0,255,127', 'spring[ \-]?green1?',
  315.     '  0,255,255', 'cyan1?',
  316.     '  3,  3,  3', 'gr[ae]y1',
  317.     '  5,  5,  5', 'gr[ae]y2',
  318.     '  8,  8,  8', 'gr[ae]y3',
  319.     ' 10, 10, 10', 'gr[ae]y4',
  320.     ' 13, 13, 13', 'gr[ae]y5',
  321.     ' 15, 15, 15', 'gr[ae]y6',
  322.     ' 16, 78,139', 'dodgerblue4',
  323.     ' 18, 18, 18', 'gr[ae]y7',
  324.     ' 20, 20, 20', 'gr[ae]y8',
  325.     ' 23, 23, 23', 'gr[ae]y9',
  326.     ' 24,116,205', 'dodgerblue3',
  327.     ' 25, 25,112', 'midnight[ \-]?blue',
  328.     ' 26, 26, 26', 'gr[ae]y10',
  329.     ' 28, 28, 28', 'gr[ae]y11',
  330.     ' 28,134,238', 'dodgerblue2',
  331.     ' 30,144,255', 'dodger[ \-]?blue1?',
  332.     ' 31, 31, 31', 'gr[ae]y12',
  333.     ' 32,178,170', 'light[ \-]?sea[ \-]?green',
  334.     ' 33, 33, 33', 'gr[ae]y13',
  335.     ' 34,139, 34', 'forest[ \-]?green',
  336.     ' 36, 36, 36', 'gr[ae]y14',
  337.     ' 38, 38, 38', 'gr[ae]y15',
  338.     ' 39, 64,139', 'royalblue4',
  339.     ' 41, 41, 41', 'gr[ae]y16',
  340.     ' 43, 43, 43', 'gr[ae]y17',
  341.     ' 46, 46, 46', 'gr[ae]y18',
  342.     ' 46,139, 87', 'sea[ \-]?green4?',
  343.     ' 47, 79, 79', 'dark( slate gr[ae]|-slate-gr[ae]|slategr[ae])y',
  344.     ' 48, 48, 48', 'gr[ae]y19',
  345.     ' 50,205, 50', 'lime[ \-]?green',
  346.     ' 51, 51, 51', 'gr[ae]y20',
  347.     ' 54, 54, 54', 'gr[ae]y21',
  348.     ' 54,100,139', 'steelblue4',
  349.     ' 56, 56, 56', 'gr[ae]y22',
  350.     ' 58, 95,205', 'royalblue3',
  351.     ' 59, 59, 59', 'gr[ae]y23',
  352.     ' 60,179,113', 'medium[ \-]?sea[ \-]?green',
  353.     ' 61, 61, 61', 'gr[ae]y24',
  354.     ' 64, 64, 64', 'gr[ae]y25',
  355.     ' 64,224,208', 'turquoise',
  356.     ' 65,105,225', 'royal[ \-]?blue',
  357.     ' 66, 66, 66', 'gr[ae]y26',
  358.     ' 67,110,238', 'royalblue2',
  359.     ' 67,205,128', 'seagreen3',
  360.     ' 69, 69, 69', 'gr[ae]y27',
  361.     ' 69,139,  0', 'chartreuse4',
  362.     ' 69,139,116', 'aquamarine4',
  363.     ' 70,130,180', 'steel[ \-]?blue',
  364.     ' 71, 60,139', 'slateblue4',
  365.     ' 71, 71, 71', 'gr[ae]y28',
  366.     ' 72, 61,139', 'dark[ \-]?slate[ \-]?blue',
  367.     ' 72,118,255', 'royalblue1',
  368.     ' 72,209,204', 'medium[ \-]?turquoise',
  369.     ' 74, 74, 74', 'gr[ae]y29',
  370.     ' 74,112,139', 'skyblue4',
  371.     ' 77, 77, 77', 'gr[ae]y30',
  372.     ' 78,238,148', 'seagreen2',
  373.     ' 79, 79, 79', 'gr[ae]y31',
  374.     ' 79,148,205', 'steelblue3',
  375.     ' 82, 82, 82', 'gr[ae]y32',
  376.     ' 82,139,139', 'darkslategray4',
  377.     ' 83,134,139', 'cadetblue4',
  378.     ' 84, 84, 84', 'gr[ae]y33',
  379.     ' 84,139, 84', 'palegreen4',
  380.     ' 84,255,159', 'seagreen1',
  381.     ' 85, 26,139', 'purple4',
  382.     ' 85,107, 47', 'dark[ \-]?olive[ \-]?green',
  383.     ' 87, 87, 87', 'gr[ae]y34',
  384.     ' 89, 89, 89', 'gr[ae]y35',
  385.     ' 92, 92, 92', 'gr[ae]y36',
  386.     ' 92,172,238', 'steelblue2',
  387.     ' 93, 71,139', 'mediumpurple4',
  388.     ' 94, 94, 94', 'gr[ae]y37',
  389.     ' 95,158,160', 'cadet[ \-]?blue',
  390.     ' 96,123,139', 'lightskyblue4',
  391.     ' 97, 97, 97', 'gr[ae]y38',
  392.     ' 99, 99, 99', 'gr[ae]y39',
  393.     ' 99,184,255', 'steelblue1',
  394.     '100,149,237', 'cornflower[ \-]?blue',
  395.     '102,102,102', 'gr[ae]y40',
  396.     '102,139,139', 'paleturquoise4',
  397.     '102,205,  0', 'chartreuse3',
  398.     '102,205,170', 'aquamarine3|medium[ \-]?aquamarine',
  399.     '104, 34,139', 'darkorchid4',
  400.     '104,131,139', 'lightblue4',
  401.     '105, 89,205', 'slateblue3',
  402.     '105,105,105', 'dim( gr[ae]|-gr[ae]|gr[ae])y|gr[ae]y41',
  403.     '105,139, 34', 'olivedrab4',
  404.     '105,139,105', 'darkseagreen4',
  405.     '106, 90,205', 'slate[ \-]?blue',
  406.     '107,107,107', 'gr[ae]y42',
  407.     '107,142, 35', 'olive[ \-]?drab',
  408.     '108,123,139', 'slategray4',
  409.     '108,166,205', 'skyblue3',
  410.     '110,110,110', 'gr[ae]y43',
  411.     '110,123,139', 'lightsteelblue4',
  412.     '110,139, 61', 'darkolivegreen4',
  413.     '112,112,112', 'gr[ae]y44',
  414.     '112,128,144', 'slate( gr[ae]|-gr[ae]|gr[ae])y',
  415.     '115,115,115', 'gr[ae]y45',
  416.     '117,117,117', 'gr[ae]y46',
  417.     '118,238,  0', 'chartreuse2',
  418.     '118,238,198', 'aquamarine2',
  419.     '119,136,153', 'light( slate gr[ae]|-slate-gr[ae]|slategr[ae])y',
  420.     '120,120,120', 'gr[ae]y47',
  421.     '121,205,205', 'darkslategray3',
  422.     '122, 55,139', 'mediumorchid4',
  423.     '122,103,238', 'slateblue2',
  424.     '122,122,122', 'gr[ae]y48',
  425.     '122,139,139', 'lightcyan4',
  426.     '122,197,205', 'cadetblue3',
  427.     '123,104,238', 'medium[ \-]?slate[ \-]?blue',
  428.     '124,205,124', 'palegreen3',
  429.     '124,252,  0', 'lawn[ \-]?green',
  430.     '125, 38,205', 'purple3',
  431.     '125,125,125', 'gr[ae]y49',
  432.     '126,192,238', 'skyblue2',
  433.     '127,127,127', 'gr[ae]y50',
  434.     '127,255,  0', 'chartreuse1?',
  435.     '127,255,212', 'aquamarine1?',
  436.     '130,130,130', 'gr[ae]y51',
  437.     '131,111,255', 'slateblue1',
  438.     '131,139,131', 'honeydew4',
  439.     '131,139,139', 'azure4',
  440.     '132,112,255', 'light[ \-]?slate[ \-]?blue',
  441.     '133,133,133', 'gr[ae]y52',
  442.     '135,135,135', 'gr[ae]y53',
  443.     '135,206,235', 'sky[ \-]?blue',
  444.     '135,206,250', 'light[ \-]?sky[ \-]?blue',
  445.     '135,206,255', 'skyblue1',
  446.     '137,104,205', 'mediumpurple3',
  447.     '138, 43,226', 'blue[ \-]?violet',
  448.     '138,138,138', 'gr[ae]y54',
  449.     '139,  0,  0', 'red4',
  450.     '139,  0,139', 'magenta4',
  451.     '139, 10, 80', 'deeppink4',
  452.     '139, 26, 26', 'firebrick4',
  453.     '139, 28, 98', 'maroon4',
  454.     '139, 34, 82', 'violetred4',
  455.     '139, 35, 35', 'brown4',
  456.     '139, 37,  0', 'orangered4',
  457.     '139, 54, 38', 'tomato4',
  458.     '139, 58, 58', 'indianred4',
  459.     '139, 58, 98', 'hotpink4',
  460.     '139, 62, 47', 'coral4',
  461.     '139, 69,  0', 'darkorange4',
  462.     '139, 69, 19', 'chocolate4|saddle[ \-]?brown',
  463.     '139, 71, 38', 'sienna4',
  464.     '139, 71, 93', 'palevioletred4',
  465.     '139, 71,137', 'orchid4',
  466.     '139, 76, 57', 'salmon4',
  467.     '139, 87, 66', 'lightsalmon4',
  468.     '139, 90,  0', 'orange4',
  469.     '139, 90, 43', 'tan4',
  470.     '139, 95,101', 'lightpink4',
  471.     '139, 99,108', 'pink4',
  472.     '139,101,  8', 'darkgoldenrod4',
  473.     '139,102,139', 'plum4',
  474.     '139,105, 20', 'goldenrod4',
  475.     '139,105,105', 'rosybrown4',
  476.     '139,115, 85', 'burlywood4',
  477.     '139,117,  0', 'gold4',
  478.     '139,119,101', 'peachpuff4',
  479.     '139,121, 94', 'navajowhite4',
  480.     '139,123,139', 'thistle4',
  481.     '139,125,107', 'bisque4',
  482.     '139,125,123', 'mistyrose4',
  483.     '139,126,102', 'wheat4',
  484.     '139,129, 76', 'lightgoldenrod4',
  485.     '139,131,120', 'antiquewhite4',
  486.     '139,131,134', 'lavenderblush4',
  487.     '139,134, 78', 'khaki4',
  488.     '139,134,130', 'seashell4',
  489.     '139,136,120', 'cornsilk4',
  490.     '139,137,112', 'lemonchiffon4',
  491.     '139,137,137', 'snow4',
  492.     '139,139,  0', 'yellow4',
  493.     '139,139,122', 'lightyellow4',
  494.     '139,139,131', 'ivory4',
  495.     '140,140,140', 'gr[ae]y55',
  496.     '141,182,205', 'lightskyblue3',
  497.     '141,238,238', 'darkslategray2',
  498.     '142,229,238', 'cadetblue2',
  499.     '143,143,143', 'gr[ae]y56',
  500.     '143,188,143', 'dark[ \-]?sea[ \-]?green',
  501.     '144,238,144', 'palegreen2',
  502.     '145, 44,238', 'purple2',
  503.     '145,145,145', 'gr[ae]y57',
  504.     '147,112,219', 'medium[ \-]?purple',
  505.     '148,  0,211', 'dark[ \-]?violet',
  506.     '148,148,148', 'gr[ae]y58',
  507.     '150,150,150', 'gr[ae]y59',
  508.     '150,205,205', 'paleturquoise3',
  509.     '151,255,255', 'darkslategray1',
  510.     '152,245,255', 'cadetblue1',
  511.     '152,251,152', 'pale[ \-]?green',
  512.     '153, 50,204', 'dark[ \-]?orchid',
  513.     '153,153,153', 'gr[ae]y60',
  514.     '154, 50,205', 'darkorchid3',
  515.     '154,192,205', 'lightblue3',
  516.     '154,205, 50', 'olivedrab3|yellow[ \-]?green',
  517.     '154,255,154', 'palegreen1',
  518.     '155, 48,255', 'purple1',
  519.     '155,205,155', 'darkseagreen3',
  520.     '156,156,156', 'gr[ae]y61',
  521.     '158,158,158', 'gr[ae]y62',
  522.     '159,121,238', 'mediumpurple2',
  523.     '159,182,205', 'slategray3',
  524.     '160, 32,240', 'purple',
  525.     '160, 82, 45', 'sienna',
  526.     '161,161,161', 'gr[ae]y63',
  527.     '162,181,205', 'lightsteelblue3',
  528.     '162,205, 90', 'darkolivegreen3',
  529.     '163,163,163', 'gr[ae]y64',
  530.     '164,211,238', 'lightskyblue2',
  531.     '165, 42, 42', 'brown',
  532.     '166,166,166', 'gr[ae]y65',
  533.     '168,168,168', 'gr[ae]y66',
  534.     '171,130,255', 'mediumpurple1',
  535.     '171,171,171', 'gr[ae]y67',
  536.     '173,173,173', 'gr[ae]y68',
  537.     '173,216,230', 'light[ \-]?blue',
  538.     '173,255, 47', 'green[ \-]?yellow',
  539.     '174,238,238', 'paleturquoise2',
  540.     '175,238,238', 'pale[ \-]?turquoise',
  541.     '176, 48, 96', 'maroon',
  542.     '176,176,176', 'gr[ae]y69',
  543.     '176,196,222', 'light[ \-]?steel[ \-]?blue',
  544.     '176,224,230', 'powder[ \-]?blue',
  545.     '176,226,255', 'lightskyblue1',
  546.     '178, 34, 34', 'firebrick',
  547.     '178, 58,238', 'darkorchid2',
  548.     '178,223,238', 'lightblue2',
  549.     '179,179,179', 'gr[ae]y70',
  550.     '179,238, 58', 'olivedrab2',
  551.     '180, 82,205', 'mediumorchid3',
  552.     '180,205,205', 'lightcyan3',
  553.     '180,238,180', 'darkseagreen2',
  554.     '181,181,181', 'gr[ae]y71',
  555.     '184,134, 11', 'dark[ \-]?goldenrod',
  556.     '184,184,184', 'gr[ae]y72',
  557.     '185,211,238', 'slategray2',
  558.     '186, 85,211', 'medium[ \-]?orchid',
  559.     '186,186,186', 'gr[ae]y73',
  560.     '187,255,255', 'paleturquoise1',
  561.     '188,143,143', 'rosy[ \-]?brown',
  562.     '188,210,238', 'lightsteelblue2',
  563.     '188,238,104', 'darkolivegreen2',
  564.     '189,183,107', 'dark[ \-]?khaki',
  565.     '189,189,189', 'gr[ae]y74',
  566.     '190,190,190', 'gr[ae]y',
  567.     '191, 62,255', 'darkorchid1',
  568.     '191,191,191', 'gr[ae]y75',
  569.     '191,239,255', 'lightblue1',
  570.     '192,255, 62', 'olivedrab1',
  571.     '193,205,193', 'honeydew3',
  572.     '193,205,205', 'azure3',
  573.     '193,255,193', 'darkseagreen1',
  574.     '194,194,194', 'gr[ae]y76',
  575.     '196,196,196', 'gr[ae]y77',
  576.     '198,226,255', 'slategray1',
  577.     '199, 21,133', 'medium[ \-]?violet[ \-]?red',
  578.     '199,199,199', 'gr[ae]y78',
  579.     '201,201,201', 'gr[ae]y79',
  580.     '202,225,255', 'lightsteelblue1',
  581.     '202,255,112', 'darkolivegreen1',
  582.     '204,204,204', 'gr[ae]y80',
  583.     '205,  0,  0', 'red3',
  584.     '205,  0,205', 'magenta3',
  585.     '205, 16,118', 'deeppink3',
  586.     '205, 38, 38', 'firebrick3',
  587.     '205, 41,144', 'maroon3',
  588.     '205, 50,120', 'violetred3',
  589.     '205, 51, 51', 'brown3',
  590.     '205, 55,  0', 'orangered3',
  591.     '205, 79, 57', 'tomato3',
  592.     '205, 85, 85', 'indianred3',
  593.     '205, 91, 69', 'coral3',
  594.     '205, 92, 92', 'indian[ \-]?red',
  595.     '205, 96,144', 'hotpink3',
  596.     '205,102,  0', 'darkorange3',
  597.     '205,102, 29', 'chocolate3',
  598.     '205,104, 57', 'sienna3',
  599.     '205,104,137', 'palevioletred3',
  600.     '205,105,201', 'orchid3',
  601.     '205,112, 84', 'salmon3',
  602.     '205,129, 98', 'lightsalmon3',
  603.     '205,133,  0', 'orange3',
  604.     '205,133, 63', 'peru|tan3',
  605.     '205,140,149', 'lightpink3',
  606.     '205,145,158', 'pink3',
  607.     '205,149, 12', 'darkgoldenrod3',
  608.     '205,150,205', 'plum3',
  609.     '205,155, 29', 'goldenrod3',
  610.     '205,155,155', 'rosybrown3',
  611.     '205,170,125', 'burlywood3',
  612.     '205,173,  0', 'gold3',
  613.     '205,175,149', 'peachpuff3',
  614.     '205,179,139', 'navajowhite3',
  615.     '205,181,205', 'thistle3',
  616.     '205,183,158', 'bisque3',
  617.     '205,183,181', 'mistyrose3',
  618.     '205,186,150', 'wheat3',
  619.     '205,190,112', 'lightgoldenrod3',
  620.     '205,192,176', 'antiquewhite3',
  621.     '205,193,197', 'lavenderblush3',
  622.     '205,197,191', 'seashell3',
  623.     '205,198,115', 'khaki3',
  624.     '205,200,177', 'cornsilk3',
  625.     '205,201,165', 'lemonchiffon3',
  626.     '205,201,201', 'snow3',
  627.     '205,205,  0', 'yellow3',
  628.     '205,205,180', 'lightyellow3',
  629.     '205,205,193', 'ivory3',
  630.     '207,207,207', 'gr[ae]y81',
  631.     '208, 32,144', 'violet[ \-]?red',
  632.     '209, 95,238', 'mediumorchid2',
  633.     '209,209,209', 'gr[ae]y82',
  634.     '209,238,238', 'lightcyan2',
  635.     '210,105, 30', 'chocolate',
  636.     '210,180,140', 'tan',
  637.     '211,211,211', 'light( gr[ae]|-gr[ae]|gr[ae])y',
  638.     '212,212,212', 'gr[ae]y83',
  639.     '214,214,214', 'gr[ae]y84',
  640.     '216,191,216', 'thistle',
  641.     '217,217,217', 'gr[ae]y85',
  642.     '218,112,214', 'orchid',
  643.     '218,165, 32', 'goldenrod',
  644.     '219,112,147', 'pale[ \-]?violet[ \-]?red',
  645.     '219,219,219', 'gr[ae]y86',
  646.     '220,220,220', 'gainsboro',
  647.     '221,160,221', 'plum',
  648.     '222,184,135', 'burlywood',
  649.     '222,222,222', 'gr[ae]y87',
  650.     '224,102,255', 'mediumorchid1',
  651.     '224,224,224', 'gr[ae]y88',
  652.     '224,238,224', 'honeydew2',
  653.     '224,238,238', 'azure2',
  654.     '224,255,255', 'light[ \-]?cyan1?',
  655.     '227,227,227', 'gr[ae]y89',
  656.     '229,229,229', 'gr[ae]y90',
  657.     '230,230,250', 'lavender',
  658.     '232,232,232', 'gr[ae]y91',
  659.     '233,150,122', 'dark[ \-]?salmon',
  660.     '235,235,235', 'gr[ae]y92',
  661.     '237,237,237', 'gr[ae]y93',
  662.     '238,  0,  0', 'red2',
  663.     '238,  0,238', 'magenta2',
  664.     '238, 18,137', 'deeppink2',
  665.     '238, 44, 44', 'firebrick2',
  666.     '238, 48,167', 'maroon2',
  667.     '238, 58,140', 'violetred2',
  668.     '238, 59, 59', 'brown2',
  669.     '238, 64,  0', 'orangered2',
  670.     '238, 92, 66', 'tomato2',
  671.     '238, 99, 99', 'indianred2',
  672.     '238,106, 80', 'coral2',
  673.     '238,106,167', 'hotpink2',
  674.     '238,118,  0', 'darkorange2',
  675.     '238,118, 33', 'chocolate2',
  676.     '238,121, 66', 'sienna2',
  677.     '238,121,159', 'palevioletred2',
  678.     '238,122,233', 'orchid2',
  679.     '238,130, 98', 'salmon2',
  680.     '238,130,238', 'violet',
  681.     '238,149,114', 'lightsalmon2',
  682.     '238,154,  0', 'orange2',
  683.     '238,154, 73', 'tan2',
  684.     '238,162,173', 'lightpink2',
  685.     '238,169,184', 'pink2',
  686.     '238,173, 14', 'darkgoldenrod2',
  687.     '238,174,238', 'plum2',
  688.     '238,180, 34', 'goldenrod2',
  689.     '238,180,180', 'rosybrown2',
  690.     '238,197,145', 'burlywood2',
  691.     '238,201,  0', 'gold2',
  692.     '238,203,173', 'peachpuff2',
  693.     '238,207,161', 'navajowhite2',
  694.     '238,210,238', 'thistle2',
  695.     '238,213,183', 'bisque2',
  696.     '238,213,210', 'mistyrose2',
  697.     '238,216,174', 'wheat2',
  698.     '238,220,130', 'lightgoldenrod2',
  699.     '238,221,130', 'light[ \-]?goldenrod',
  700.     '238,223,204', 'antiquewhite2',
  701.     '238,224,229', 'lavenderblush2',
  702.     '238,229,222', 'seashell2',
  703.     '238,230,133', 'khaki2',
  704.     '238,232,170', 'pale[ \-]?goldenrod',
  705.     '238,232,205', 'cornsilk2',
  706.     '238,233,191', 'lemonchiffon2',
  707.     '238,233,233', 'snow2',
  708.     '238,238,  0', 'yellow2',
  709.     '238,238,209', 'lightyellow2',
  710.     '238,238,224', 'ivory2',
  711.     '240,128,128', 'light[ \-]?coral',
  712.     '240,230,140', 'khaki',
  713.     '240,240,240', 'gr[ae]y94',
  714.     '240,248,255', 'alice[ \-]?blue',
  715.     '240,255,240', 'honeydew1?',
  716.     '240,255,255', 'azure1?',
  717.     '242,242,242', 'gr[ae]y95',
  718.     '244,164, 96', 'sandy[ \-]?brown',
  719.     '245,222,179', 'wheat',
  720.     '245,245,220', 'beige',
  721.     '245,245,245', 'gr[ae]y96|white[ \-]?smoke',
  722.     '245,255,250', 'mint[ \-]?cream',
  723.     '247,247,247', 'gr[ae]y97',
  724.     '248,248,255', 'ghost[ \-]?white',
  725.     '250,128,114', 'salmon',
  726.     '250,235,215', 'antique[ \-]?white',
  727.     '250,240,230', 'linen',
  728.     '250,250,210', 'light[ \-]?goldenrod[ \-]?yellow',
  729.     '250,250,250', 'gr[ae]y98',
  730.     '252,252,252', 'gr[ae]y99',
  731.     '253,245,230', 'old[ \-]?lace',
  732.     '255,  0,  0', 'red1?',
  733.     '255,  0,255', 'magenta1?',
  734.     '255, 20,147', 'deep[ \-]?pink1?',
  735.     '255, 48, 48', 'firebrick1',
  736.     '255, 52,179', 'maroon1',
  737.     '255, 62,150', 'violetred1',
  738.     '255, 64, 64', 'brown1',
  739.     '255, 69,  0', 'orange[ \-]?red1?',
  740.     '255, 99, 71', 'tomato1?',
  741.     '255,105,180', 'hot[ \-]?pink',
  742.     '255,106,106', 'indianred1',
  743.     '255,110,180', 'hotpink1',
  744.     '255,114, 86', 'coral1',
  745.     '255,127,  0', 'darkorange1',
  746.     '255,127, 36', 'chocolate1',
  747.     '255,127, 80', 'coral',
  748.     '255,130, 71', 'sienna1',
  749.     '255,130,171', 'palevioletred1',
  750.     '255,131,250', 'orchid1',
  751.     '255,140,  0', 'dark[ \-]?orange',
  752.     '255,140,105', 'salmon1',
  753.     '255,160,122', 'light[ \-]?salmon1?',
  754.     '255,165,  0', 'orange1?',
  755.     '255,165, 79', 'tan1',
  756.     '255,174,185', 'lightpink1',
  757.     '255,181,197', 'pink1',
  758.     '255,182,193', 'light[ \-]?pink',
  759.     '255,185, 15', 'darkgoldenrod1',
  760.     '255,187,255', 'plum1',
  761.     '255,192,203', 'pink',
  762.     '255,193, 37', 'goldenrod1',
  763.     '255,193,193', 'rosybrown1',
  764.     '255,211,155', 'burlywood1',
  765.     '255,215,  0', 'gold1?',
  766.     '255,218,185', 'peach[ \-]?puff1?',
  767.     '255,222,173', 'navajo[ \-]?white1?',
  768.     '255,225,255', 'thistle1',
  769.     '255,228,181', 'moccasin',
  770.     '255,228,196', 'bisque1?',
  771.     '255,228,225', 'misty[ \-]?rose1?',
  772.     '255,231,186', 'wheat1',
  773.     '255,235,205', 'blanched[ \-]?almond',
  774.     '255,236,139', 'lightgoldenrod1',
  775.     '255,239,213', 'papaya[ \-]?whip',
  776.     '255,239,219', 'antiquewhite1',
  777.     '255,240,245', 'lavender[ \-]?blush1?',
  778.     '255,245,238', 'seashell1?',
  779.     '255,246,143', 'khaki1',
  780.     '255,248,220', 'cornsilk1?',
  781.     '255,250,205', 'lemon[ \-]?chiffon1?',
  782.     '255,250,240', 'floral[ \-]?white',
  783.     '255,250,250', 'snow1?',
  784.     '255,255,  0', 'yellow1?',
  785.     '255,255,224', 'light[ \-]?yellow1?',
  786.     '255,255,240', 'ivory1?',
  787.     '255,255,255', 'gr[ae]y100|white',
  788.     );
  789.     while (($val, $regex) = each %rgb) {
  790.     return split(',', $val) if m/^$regex$/i;
  791.     }
  792.  
  793. }
  794. __END__
  795.